package com.lei.sqlJsp.service.Impl;

import java.util.List;

import com.lei.sqlJsp.dao.GoodsDao;
import com.lei.sqlJsp.dao.Impl.GoodsDaoImpl;
import com.lei.sqlJsp.entity.GoodsEntity;
import com.lei.sqlJsp.entity.Page;
import com.lei.sqlJsp.service.GoodsService;

public class GoodsServiceImpl implements GoodsService {
private GoodsDao goodsDao=new GoodsDaoImpl();
	@Override
	public void add(GoodsEntity shopName) {
		goodsDao.add(shopName);
		
	}

	@Override
	public void delete(Long id) {
		goodsDao.delete(id);
		
	}

	@Override
	public void update(GoodsEntity id) {
	goodsDao.update(id);
		
	}

	@Override
	public List<GoodsEntity> list() {
		
		return goodsDao.listAll();
	}

	@Override
	public Page<GoodsEntity> page(int currentPage, int pageSize) {
//		查询数据库有多少条数据
		int count =goodsDao.getCount();
//		根据数据库分页查询得到limit  起始页
		List<GoodsEntity> data=goodsDao.getPage(currentPage, pageSize);
		int totalPage=count/pageSize;
		totalPage+=count%pageSize==0?0:1;
		Page<GoodsEntity> page=new Page<>(count, totalPage, currentPage, data);
		return page;

	}

	@Override
	public GoodsEntity getById(Long id) {
		// TODO Auto-generated method stub
		return goodsDao.getById(id);
	}

}
